
import {getDetails} from '@/api/admin/user'
import { rule } from "@/util/validateRules";
import store from '@/store'


var validateUsername = (rule, value, callback) => {
  if(value!=''){
    getDetails(value).then(response => {
      if (window.boxType === 'edit') callback()
      const result = response.data.data
      if (result !== null) {
        callback(new Error('用户名已经存在'))
      } else {
        callback()
      }
    })
  }
}
/**
   * 校验密码 数字、字母大小写、特殊字符
   */

var validatorPassword = (rule, value, callback) => {   
    let acount =/^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[!#@*&.])[a-zA-Z\d!#@*&.]*$/;	
	if (value && (!(acount).test(value))) {
      callback(new Error('密码必须包括大小写字母、数字、特殊符号且至少8位字符组成'))
    } else {
      callback()
    }  
};
export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  viewBtn: true,
  editBtn: true,
  delBtn: false,
  align: 'center',
  columnBtn: false,
  addBtn: true,
  column: [{
    fixed: true,
    label: 'id',
    prop: 'userId',
    span: 24,
    hide: true,
    display: false
  }, {
    label: '用户名',
    prop: 'username',
    editDisabled: true,
    slot: true,
    search: true,
    rules: [{
      required: true,
      message: '请输入用户名'
    },
      {
        min: 3,
        max: 20,
        message: '长度在 3 到 20 个字符',
        trigger: 'blur'
      },
      {validator: validateUsername, trigger: 'blur'}
    ]
  }, {
    label: '员工号',
    prop: 'userCode',
    editDisabled: true,
    rules: [{
      required: true,
      message: '请输入员工号'
    }],
    search: true
  }, {
    label: '姓名',
    prop: 'nikename',
    type: 'input',
    search: true
  }, {
    label: '密码',
    prop: 'password',
    type: 'password',
    value: '',
    hide: true,
    rules: [{
      min: 8,
      max: 20,
      message: '密码长度在 8 到 20 个字符',
      trigger: 'blur'
      },
      { validator: validatorPassword, trigger: "blur" }
	]
  }, {
    label: '所属部门',
    prop: 'deptId',
    type: 'tree',
    slot: true,
    dataType:"number",
    rules: [{
      required: true,
      message: '请选择部门',
      trigger: 'change'
    }],
    dicUrl: '/admin/dept/tree',
    props: {
      label: 'name',
      value: 'id',
      res: 'data'
    },
    disabled: true,
    value: store.getters.userInfo.deptId
  // }, {
  //   hide: true,
  //   label: '手机号',
  //   prop: 'phone',
  //   type: 'tel',
  //   value: '',
  //   rules: [{
  //     min: 11,
  //     max: 11,
  //     message: '长度在 11 个字符',
  //     trigger: 'blur'
  //   }]
  // }, {
  //   hide: true,
  //   label: 'email',
  //   prop: 'email',
  //   type: 'input',
  //   rules: [{
  //     validator: rule.emailValue, trigger: 'blur'
  //   }]
  // }, {
  //   hide: true,
  //   label: '钉钉ID',
  //   prop: 'dingdingId',
  //   type: 'input'
  }, {
    label: '角色',
    prop: 'role',
    formslot: true,
    slot: true,
    overHidden: true,
    rules: [{
      required: true,
      message: '请选择角色',
      trigger: 'blur'
    }]
  }, {
    hide: true,
    label: '线网人员',
    prop: 'belongToLine',
    type: 'switch',
    span: 24,
    dicData: [{
      label: '否',
      value: false
    }, {
      label: '是',
      value: true
    },],
    value: true,
    //display: false
  }, {
    hide: true,
    label: '线路',
    prop: 'lineCode',
    type: 'select',
    cascaderItem: ["stationCode"],
    props: {
      label: 'name',
      value: 'code'
    },
    dicUrl: "/support/swparamline/dict",
    display: false
  }, {
    hide: true,
    label: '车站',
    prop: 'stationCode',
    type: 'select',
    dicFlag: false,
    props: {
      label: 'name',
      value: 'code'
    },
    dicUrl: `/support/swparamstation/dict/{{key}}`,
    display: false
  },
  {
    label: "是否管辖线路、车站",
    type: "radio",
    prop: "isManageStation",
    hide: true,
    span: 24,
    //如果是非线网人员，也可以设置管辖线路
    //display: true, // 动态显隐控制不能删除
    dicData: [
      {
        label: "是",
        value: true
      },
      {
        label: "否",
        value: false
      }
    ],
    value: true
  },
  {
    label: "",
    labelWidth: 0,
    type: "dynamic",
    prop: "manageStations",
    span: 24,
    formslot: true,
    display: false // 动态显隐控制不能删除
  }, {
    label: '状态',
    prop: 'lockFlag',
    type: 'radio',
    slot: true,
    border:true,
    span: 24,
    rules: [{
      required: true,
      message: '请选择状态',
      trigger: 'blur'
    }],
    dicData: [{
      label: '有效',
      value: '0'
    }, {
      label: '注销',
      value: '9'
    }],
    search: true
  }, {
    width: 130,
    label: '创建时间',
    prop: 'createTime',
    type: 'datetime',
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    editDisplay: false,
    addDisplay: false
  },
  {
    label: "创建时间",
    prop: "dates1",
    type: "date",
    format: "yyyy-MM-dd",
    valueFormat: "yyyy-MM-dd",
    display: false,
    hide: true,
    search: true,
    searchRange: true,
    searchSpan: 12
  },{
    hide: false,
	search:true,
    label: '备注',
    prop: 'dingdingId',
    type: "textarea",
    span: 24
  }]
}
